home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
jpeg
/
libCLRjpeg4
/
example
/
jpaste.c
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
135 lines
/* includes */
#include <stdio.h>
#include <gl.h>
#include <device.h>
extern char * optarg;
extern int optind;
/************************************************************************
*
* usage
*
* print the usage string
*
*************************************************************************/
void
usage (char * progname)
/* complain about bad command line */
{
fprintf(stderr, "usage: %s ", progname);
fprintf(stderr, "[-n] [-o x,y] [-f] file\n\n");
fprintf(stderr, "-n do not diplay a border on the window\n");
fprintf(stderr, "-o x,y start the window's lower-left corner at this\n");
fprintf(stderr, " screen position (relative to bottom left corner\n");
fprintf(stderr, "-f start the program in the foreground\n");
fprintf(stderr, "file the name of the file to display\n");
fprintf(stderr, "\n");
fprintf(stderr,"This program will open a window and display a jpeg\n");
fprintf(stderr,"image (if it is in JFIF format and does NOT use\n");
fprintf(stderr,"arithmetic coding). The decoding process utilizes\n");
fprintf(stderr,"the Independent JPEG Group's software (%s).\n",GetJPEGVersion());
fprintf(stderr,"IRIS GL(tm) Adaption is\n");
fprintf(stderr,"(c) 1992 Rodney Hoinkes, Centre for Landscape Research\n");
fprintf(stderr,"This software is public domain.\n");
exit(2);
}
char WindowName[256];
char NoBorder = 0, NoFork = 0, PrefOrg = FALSE;
int window_x, window_y;
main(argc,argv)
int argc;
char *argv[];
{
int c;
long *imageptr;
int xsize, ysize;
while ((c = getopt(argc, argv, "nfo:")) != -1) {
switch (c) {
case 'n':
NoBorder = 1;
break;
case 'f':
NoFork = 1;
break;
case 'o':
if (optarg == NULL)
usage(argv[0]);
if (sscanf(optarg, "%d,%d", &window_x, &window_y) != 2)
usage(argv[0]);
PrefOrg = TRUE;
break;
case '?':
default:
usage(argv[0]);
break;
}
}
if (optind != argc-1) usage(argv[0]);
/* Select the input files */
if (optind < argc-1) {
fprintf(stderr, "%s: only one input file allowed\n", argv[0]);
usage(argv[0]);
}
strcpy(WindowName,argv[optind]);
imageptr = (long *)LoadJPEGImagePtr(WindowName,&xsize,&ysize);
SetupGraphics(xsize,ysize);
lrectwrite(0,0,xsize-1,ysize-1,imageptr);
ManageWindow(imageptr,xsize,ysize);
}
SetupGraphics(int xsize,int ysize) {
/* Eric Willaims, williams@sgi.com
-- add command line options to GL interface */
/* open the window */
if (PrefOrg) {
prefposition(window_x, window_x + xsize - 1,
window_y, window_y + ysize - 1);
if (NoBorder) noborder();
if (NoFork) foreground();
winopen(WindowName);
prefsize(xsize,ysize);
if (NoBorder) noborder();
winconstraints();
} else {
prefsize(xsize,ysize);
if (NoBorder) noborder();
if (NoFork) foreground();
winopen(WindowName);
}
/* set the display mode for the image */
RGBmode();
singlebuffer();
gconfig();
cpack(0xffffffff);
clear();
}
ManageWindow(long *imageptr,int xsize,int ysize) {
long val;
short type;
while(1) {
if(qtest()) {
val = qread(&type);
switch(val) {
case REDRAW:
case INPUTCHANGE:
lrectwrite(0,0,xsize-1,ysize-1,imageptr);
break;
}
}
}
}